package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @author 韩先楚
 */
@RestController
@RequestMapping("/admin/shop")
@Api(tags = "管理端-商铺状态管理")
@Slf4j
public class ShopController {

    @Autowired
    private StringRedisTemplate redis;

    /**
     * 修改商铺状态
     * @param status 状态
     * @return Result
     * @author 韩先楚
     */
    @PutMapping("/{status}")
    @ApiOperation(value = "修改商铺状态", notes = "修改商铺状态")
    public Result  updateShopStatus(@PathVariable("status") Integer status) {
        log.info( "修改商铺状态 {}",status);
        redis.opsForValue().set("SHOP_STATUS", status.toString());
        return Result.success();
    }

    /**
     * admin端查询商铺状态
     * @return Result
     * @author 韩先楚
     */
    @GetMapping("/status")
    @ApiOperation(value = "查询商铺状态", notes = "查询商铺状态")
    public Result<Integer> getShopStatus() {
        String status = redis.opsForValue().get("SHOP_STATUS");
        return Result.success(Integer.parseInt(status));
    }
}
